package com.eb.buybuybuy.controller;

import com.eb.buybuybuy.annotation.*;
import com.eb.buybuybuy.bean.User;
import com.eb.buybuybuy.constant.RequestMethodEnum;
import com.eb.buybuybuy.core.IOC;
import com.eb.buybuybuy.service.UserService;
import com.eb.buybuybuy.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Component
@HttpController("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @Entrance(path = "/info", method = RequestMethodEnum.GET)
    public Object info(@RequestParameter("id") String id) throws Exception {
        return userService.info(Integer.valueOf(id));
    }

    @Entrance(path = "/login", method = RequestMethodEnum.POST)
    public Object login(
            @RequestParameter("username") String username,
            @RequestParameter("password") String password,
            @SessionParameter HttpSession session
    ) throws Exception {
        userService.login(username, password, session);
        return null;
    }

    @Entrance(path = "/register", method = RequestMethodEnum.POST)
    public Object register(
            @RequestParameter("username") String username,
            @RequestParameter("password") String password,
            @SessionParameter HttpSession session
    ) throws Exception {
        userService.register(username, password, session);
        return null;
    }

    @Entrance(path = "/logout", method = RequestMethodEnum.GET)
    public Object logout(@SessionParameter HttpSession session) throws Exception {
        userService.logout(session);
        return null;
    }
}
